#include<bits/stdc++.h>
using namespace std;

int T,n,a[200005],dp[200005];
long long res(int p,int r,int b){
    if(p>n)return 0;
    int ans1=res(p+1,a[p],b),ans2=res(p+1,r,a[p]);
    if(r==a[p])ans1+=r;
    if(b==a[p])ans2+=b;
    return max(ans1,ans2);

}
int main(){
    //freopen("color.in","r",stdin);
    //freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        printf("%lld\n",res(1,-1,-1));
    }
}
